﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OPCService
{
    public partial class SettingForm : Form
    {
        public SettingForm()
        {
            InitializeComponent();
            this.Icon = new Icon("Resource/accs32.ico");
            LoadSettings();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            var settings = Properties.Settings.Default;

            settings.steamFlowLower = (int)steamFlowLower.Value;
            settings.steamFlowUpper = (int)steamFlowUpper.Value;
            settings.steamTemperatureLower = (int)steamTemperatureLower.Value;
            settings.steamTemperatureUpper = (int)steamTemperatureUpper.Value;
            settings.incineratorTemperatureLower = (int)incineratorTemperatureLower.Value;
            settings.incineratorTemperatureUpper = (int)incineratorTemperatureUpper.Value;
            settings.incineratorOxygenLower = (int)incineratorOxygenLower.Value;
            settings.incineratorOxygenUpper = (int)incineratorOxygenUpper.Value;
            settings.incineratorPressureLower = (int)incineratorPressureLower.Value;
            settings.incineratorPressureUpper = (int)incineratorPressureUpper.Value;
            settings.validDataRange = (int)validDataRange.Value;
            settings.validPeriodRange = (int)validPeriodRange.Value; 
            settings.steamFlowSettingVal = (int)steamFlowSettingVal.Value;
            settings.qibaoMax = (int)qbMax.Value;
            settings.qibaoLower = (int)qbLower.Value;
            settings.qibaoUpper = (int)qbUpper.Value;
            settings.wind1Lower = (int)wind1Lower.Value;
            settings.wind1Upper = (int)wind1Upper.Value;
            settings.wind2Lower = (int)wind2Lower.Value;
            settings.wind2Upper = (int)wind2Upper.Value;
            settings.line1BackwardPeriodLower = (int)line1BackwardPeriodLower.Value;
            settings.line1BackwardPeriodUpper = (int)line1BackwardPeriodUpper.Value;
            settings.line2BackwardPeriodLower = (int)line2BackwardPeriodLower.Value;
            settings.line2BackwardPeriodUpper = (int)line2BackwardPeriodUpper.Value;
            settings.line3BackwardPeriodLower = (int)line3BackwardPeriodLower.Value;
            settings.line3BackwardPeriodUpper = (int)line3BackwardPeriodUpper.Value;
            settings.line4BackwardPeriodLower = (int)line4BackwardPeriodLower.Value;
            settings.line4BackwardPeriodUpper = (int)line4BackwardPeriodUpper.Value;
            settings.line1ForwardPeriodLower = (int)line1ForwardPeriodLower.Value;
            settings.line1ForwardPeriodUpper = (int)line1ForwardPeriodUpper.Value;
            settings.line2ForwardPeriodLower = (int)line2ForwardPeriodLower.Value;
            settings.line2ForwardPeriodUpper = (int)line2ForwardPeriodUpper.Value;
            settings.line3ForwardPeriodLower = (int)line3ForwardPeriodLower.Value;
            settings.line3ForwardPeriodUpper = (int)line3ForwardPeriodUpper.Value;
            settings.line4ForwardPeriodLower = (int)line4ForwardPeriodLower.Value;
            settings.line4ForwardPeriodUpper = (int)line4ForwardPeriodUpper.Value;
            settings.line3TlqPeriodLower = (int)line3TlqPeriodLower.Value;
            settings.line3TlqPeriodUpper = (int)line3TlqPeriodUpper.Value;
            settings.cbAotoWrite = cbAotoWrite.Checked;
            settings.Save();

            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void LoadSettings()
        {
            var settings = Properties.Settings.Default;

            steamFlowLower.Value = settings.steamFlowLower;
            steamFlowUpper.Value = settings.steamFlowUpper;
            steamTemperatureLower.Value = settings.steamTemperatureLower;
            steamTemperatureUpper.Value = settings.steamTemperatureUpper;
            incineratorTemperatureLower.Value = settings.incineratorTemperatureLower;
            incineratorTemperatureUpper.Value = settings.incineratorTemperatureUpper;
            incineratorOxygenLower.Value = settings.incineratorOxygenLower;
            incineratorOxygenUpper.Value = settings.incineratorOxygenUpper;
            incineratorPressureLower.Value = settings.incineratorPressureLower;
            incineratorPressureUpper.Value = settings.incineratorPressureUpper;
            validDataRange.Value = settings.validDataRange;
            validPeriodRange.Value = settings.validPeriodRange;
            steamFlowSettingVal.Value = settings.steamFlowSettingVal;
            qbMax.Value = settings.qibaoMax;
            qbLower.Value = settings.qibaoLower;
            qbUpper.Value = settings.qibaoUpper;
            wind1Lower.Value = settings.wind1Lower;
            wind1Upper.Value = settings.wind1Upper;
            wind2Lower.Value = settings.wind2Lower;
            wind2Upper.Value = settings.wind2Upper;
            line1BackwardPeriodLower.Value = settings.line1BackwardPeriodLower;
            line1BackwardPeriodUpper.Value = settings.line1BackwardPeriodUpper;
            line2BackwardPeriodLower.Value = settings.line2BackwardPeriodLower;
            line2BackwardPeriodUpper.Value = settings.line2BackwardPeriodUpper;
            line3BackwardPeriodLower.Value = settings.line3BackwardPeriodLower;
            line3BackwardPeriodUpper.Value = settings.line3BackwardPeriodUpper;
            line4BackwardPeriodLower.Value = settings.line4BackwardPeriodLower;
            line4BackwardPeriodUpper.Value = settings.line4BackwardPeriodUpper;
            line1ForwardPeriodLower.Value = settings.line1ForwardPeriodLower;
            line1ForwardPeriodUpper.Value = settings.line1ForwardPeriodUpper;
            line2ForwardPeriodLower.Value = settings.line2ForwardPeriodLower;
            line2ForwardPeriodUpper.Value = settings.line2ForwardPeriodUpper;
            line3ForwardPeriodLower.Value = settings.line3ForwardPeriodLower;
            line3ForwardPeriodUpper.Value = settings.line3ForwardPeriodUpper;
            line4ForwardPeriodLower.Value = settings.line4ForwardPeriodLower;
            line4ForwardPeriodUpper.Value = settings.line4ForwardPeriodUpper;
            line3TlqPeriodLower.Value = settings.line3TlqPeriodLower;
            line3TlqPeriodUpper.Value = settings.line3TlqPeriodUpper;
            cbAotoWrite.Checked = settings.cbAotoWrite;
        }
    }
}
